//获取应用实例
const app = getApp();

Page({
    data:{
        id: 0,
        detail: null,
        nav_active_index: 0,
        nav_list: [
            {id: 1, name: '其他信息'},
            {id: 2, name: '买手完善'},
            {id: 3, name: '商品完善'},
            {id: 4, name: '通用属性'},
        ],
        list_data: [],
        now_page: 0,
        list_total: 0,
        keywords: '', 
        table_scroll_left: 0,
        stockHeaders: [
          "仓库",
          "28/44/160/37/S",
          "29/46/165/38/M",
          "30/48/170/39/L",
          "31/50/175/40/XL",
          "32/52/180/41/2XL",
          "33/54/185/42/3XL",
          "34/56/190/43/4XL",
          "35/58/195/44/5XL",
          "36/6XL",
          "38/7XL",
          "40",
          "42",
        ],
 
        

    },
    onLoad: function (options) {
        // 设置标题
        wx.setNavigationBarTitle({
            title: '预生产计划详情'
        });
        // 设置模板
        if (options.id != undefined) {
            this.setData({
                id: options.id
            });
            // 获取模板详情
            this.get_detail();
        }

        
    },

    // 表格滑动结束
    tr_boxs_scroll_end: function (e) {
        var __this = this;
        setTimeout(function () {
            __this.setData({
                table_scroll_left: e.detail.scrollLeft
            });
        }, 180);
    },

    // 获取样板详情
    get_detail: function () {
        var result = app.request_api('admin/PreProductPlan/edit', {
            id: this.data.id
        }, true, 'GET');
        result.then(res => { 
            this.setData({
                detail: res.row
            });
           
        });
    },
  
    // 预览图片
    PreviewImg: function (events) {
        var pic_arr = events.currentTarget.dataset.pic;
        if (pic_arr.length == 0) {
            return false;
        }
        // 调用
        wx.previewImage({
            current: pic_arr[0],
            urls: pic_arr
        })
    },

    // 展示更多
    showMore: function (events) {
        var index = events.currentTarget.dataset.index;
        var content = this.data.detail.bom_list[index].bom_name;
        wx.showToast({
            title: content,
            icon: 'none',
            duration: 3000,
        });
    },

    // 编辑样板
    update_page: function (events) {
        var __this = this; 
        wx.navigateTo({  
            url: '/pages/pre_product_plan/add/index?id=' + __this.data.detail.id,
            events: {
                // 当修改完成时
                changeData: function (data) {
                    // 重新请求数据
                    __this.get_detail();
                }
            }
        });
    },

    // // 关闭生产
    // template_close: function (events) {
    //     var __this = this;
    //     // 确认提示
    //     wx.showModal({
    //         title: '提示',
    //         content: '您确定要关闭生产吗',
    //         success(res) {
    //             if (res.confirm) {
    //                 __this.template_close_request();
    //             }
    //         },
    //     });
    // },
   
    // 切换选项卡
    ChangeNav: function (events) {
        var index = events.currentTarget.dataset.index;
        this.setData({
            nav_active_index: index
        });
    },

    // 预览图片
    PreviewImage: function (events) {
        var src = events.currentTarget.dataset.src;
        // 调用
        wx.previewImage({
            current: src,
            urls: [src]
        })
    },

    // 跳转到详情页
    GoDetail: function (events) {
        var __this = this;
        var total_bom_id = events.currentTarget.dataset.id;
        var template_no = events.currentTarget.dataset.no;
        // 打开详情页面
        wx.navigateTo({
            url: '/pages/wuliao_follow_detail/wuliao_follow_detail?total_bom_id=' + total_bom_id + '&template_no=' + template_no,
        });
    },


})
